package com.aldobucchi.core.comparison
{
	
	import com.aldobucchi.core.comparison.result.ComparisonResult;
	import com.aldobucchi.core.comparison.result.ComparisonResults;
	import com.aldobucchi.core.comparison.simple.ISimpleComparator;
	import com.aldobucchi.core.comparison.simple.impl.DoubleEqualSimpleComparator;
	
	
	public class ComparisonUtil
	{
		

		
		/**
		 * 
		 * Convenience method to perform comparison. It will fallback to the default comparator
		 * ( DoubleEqualComparator ) if no comparator is passed.
		 * It is used internally by most methods that take an optional comparator as argument.
		 * 
		 * Note that you CAN pass an ordered comparator ( it extends simplecomparator )
		 * 
		 * @param value1
		 * @param value2
		 * @param comparator
		 * @return 
		 * 
		 */		
		public static function compare( value1:*, value2:*, comparator:ISimpleComparator = null ):ComparisonResult
		{
			
			if ( value1 === value2 ) // cheapest comparison first
				return ComparisonResults.EQUAL;
			
			if ( comparator == null )
			{
				comparator = new DoubleEqualSimpleComparator();
			}
			return comparator.compare( value1, value2 );
		}
		
	}
	
}